package com.example.board.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.board.pojo.User;
import com.example.board.pojo.vo.PublicFilterVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface PublicFilterMapper extends BaseMapper<User> {

    @Select({
            "<script>",
            "select u.nickname label ,u.id value  ",
            " from  sys_user u ,sd_tool_man_info s ",
            " where u.id = s.user_id and u.created_at >#{parse} and u.enabled = 1 ",
            "GROUP BY u.nickname ,u.id  ",
            "</script>"
    })
    List<PublicFilterVo> findSalesMan(@Param("parse")LocalDateTime startDate);

    /**
     * 得到所有地区变树
     *
     * @return
     */
    @Select({
            "SELECT sd.province label ,  sd.city as value  ,st.name as team",
            "FROM sd_tool_man_info sd ,sys_user su ,sys_dept st",
            "WHERE sd.user_id = su.id and su.dept_id = st.id and st.deleted_at is null and st.enabled = 1 ",
            "GROUP BY  sd.province ,sd.city ,st.name "
    })
    List<PublicFilterVo> findAllCityTeam();

}
